package io.renren.security.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.renren.common.util.BeanUtils;
import io.renren.modules.sys.entity.SysUserEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

@EqualsAndHashCode(callSuper = true)
@Data
public class SecurityUser extends SysUserEntity implements UserDetails{

    private static final long serialVersionUID = -6297371765918626034L;

    private Collection<? extends GrantedAuthority> authorities;

    public SecurityUser(SysUserEntity sysUserEntity,Collection<? extends GrantedAuthority> authorities){
        BeanUtils.copyProperties(sysUserEntity,this);
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonLocked() {
        return getStatus() != 0;
    }

    @Override
    @JsonIgnore
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isEnabled() {
        return true;
    }


}
